﻿using MediatR;
using T_settlement.API.Application.Command.InvoiceCommand;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.InvoiceCommandHandlers
{
    public class DelInvoiceCommandHandlers : IRequestHandler<DelInvoiceCommand, int>
    {
        private readonly InvoiceRepository invoiceRepository;

        public DelInvoiceCommandHandlers(InvoiceRepository invoiceRepository)
        {
            this.invoiceRepository = invoiceRepository;
        }

        public async Task<int> Handle(DelInvoiceCommand request, CancellationToken cancellationToken)
        {
            var res = await invoiceRepository.GetModelAsync(request.InvoiceId);
            res.IsDel = true;
            var info = await invoiceRepository.UpdateAsync(res);
            return info;
        }
    }
}
